<template>
  <div class="notice-dialog">
    <el-dialog
      :title="titleFlag ? '修改公告' : '添加公告'"
      :visible.sync="show"
      :before-close="close"
    >
      <el-form :model="addForm" ref="addForm">
        <el-form-item label="问题地址">
          <el-input v-model="addForm.address"></el-input>
        </el-form-item>
        <el-form-item label="问题描述">
          <el-input v-model="addForm.content"></el-input>
        </el-form-item>
        <el-form-item label="业主电话">
          <el-input v-model="addForm.tel"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="addNotice">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>


<script>
import http from "../../api/goods";
export default {
  props: {
    // 标头
    titleFlag: {
      type: Boolean,
      default: false,
    },
    show: {
      type: Boolean,
      default: false,
    },
    //父组件传过来值
    updateData: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      // 公告信息
      addForm: {
        id: 0,
        address: "",
        content: "",
        userid: 1,
        tel: "",
        type: 1,
        state: 1,
        addtime: "2021-10-22 17:01:40.0",
      },
    };
  },
  methods: {
    // 取消
    close() {
      this.$emit("close", false); //子元素像父元素传值
    },
    // 确定
    async addNotice() {
      let msg = !this.addForm.id ? "添加成功" : "修改成功";
      const { errCode } = await http.questionswadd(this.addForm);
      // console.log(errCode);1
      if (errCode === 10000) {
        this.$message.success(msg); //成功失败特性
        this.$emit("close", false, undefined, 1); //关闭窗口
        this.$refs.addForm.resetFields(); //重置input
      }
    },
  },
  watch: {
    updateData(newVal) {
      this.addForm = newVal;
    },
  },
};
</script>


<style>
</style> 
